import request from "@/utils/request";
import type { loginForm, userInfo, studentInfo } from "./type";

// 枚举
enum API {
  LOGIN_URL = "/user/login",
  USERINFO_URL = "/user/userInfo",
  STUDENT_LOGIN = "/user/studentLogin",
  REGISTER = "/user/register",
  STUDENTINFO = "/user/studentInfo",
}
// 登录接口方法
export const reqLogin = (data: loginForm) => {
  const param = new URLSearchParams();
  for (let key in data) {
    param.append(key, data[key]);
  }
  return request.post(API.LOGIN_URL, param);
};
export const reqUserInfo = () => request.get(API.USERINFO_URL);

export const LoginStudent = (data: loginForm) => {
  const param = new URLSearchParams();
  for (let key in data) {
    param.append(key, data[key]);
  }
  return request.post(API.STUDENT_LOGIN, param);
};
export const RegisterStudent = (data: loginForm) => {
  const param = new URLSearchParams();
  for (let key in data) {
    param.append(key, data[key]);
  }
  return request.post(API.REGISTER, param);
};
export const reqStudentInfo = () => request.get(API.STUDENTINFO);
// 修改信息

export const updateUserInfo = (userInfo: userInfo) => {
  return request.put("/user/updateInfo", userInfo);
};
export const updateStudentInfo = (student: studentInfo) => {
  return request.put("/user/updateStudentInfo", student);
};
export const getUserName = (userId: number) => {
  return request.get(`${"/user/userName"}/${userId}`);
};
// 获取所有学生
export const getAllStudent = () => {
  return request.get("/user/getAllstudent");
};
